package com.coreservlets.jsf.ss13;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;

@ManagedBean
public class Employee
{
	private String firstName;
	private String middleName;
	private String lastName;
	private String employeeID;
	private int buildingNumber;
	public String getFirstName() {
		return firstName;
	}
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	public String getMiddleName() {
		return middleName;
	}
	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}
	public String getLastName() {
		return lastName;
	}
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	public String getEmployeeID() {
		return employeeID;
	}
	public void setEmployeeID(String employeeID) {
		this.employeeID = employeeID;
	}
	public int getBuildingNumber() {
		return buildingNumber;
	}
	public void setBuildingNumber(int buildingNumber) {
		this.buildingNumber = buildingNumber;
	}
	
	public String doPost()
	{
		return( "result-page" );
	}
	
	public void validateBuildings(FacesContext context, UIComponent componentToValidate, Object value ) throws ValidatorException
	{
		int valor = (Integer) value;
		
		if( valor == 3 || valor == 17 || valor == 41 )
		{
			FacesMessage message = new FacesMessage( "Building number " + valor + " is not available" );
			
			throw new ValidatorException( message );
		}
	}
}
